/*
 * Created by SharpDevelop.
 * User: nebulom
 * Date: 9/3/2009
 * Time: 9:45 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using PilotFish.Model;

namespace PilotFish.Gui
{
	/// <summary>
	/// Description of PatientForm.
	/// </summary>
	public partial class PatientForm : BaseForm
	{
		public PatientForm() : this(new Patient())
		{
			
		}
		
		public PatientForm(Patient p)
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			Model = p;
			comboBoxChangeTabs.SelectedIndex = 0;
		}
		
		protected override void OnModelChanged(EventArgs e)
		{
			base.OnModelChanged(e);
			Patient p = Model as Patient;
			if (p.LegalName != null) {
				textBoxTitle.Text = p.LegalName.Title;
				textBoxLastName.Text = p.LegalName.Last;
				textBoxFirstName.Text = p.LegalName.First;
				textBoxMI.Text = p.LegalName.Middle;
			}
		}
		
		void ButtonOkClick(object sender, EventArgs e)
		{
			Patient p = Model as Patient;
			p.LegalName = new Name(textBoxTitle.Text, textBoxLastName.Text, textBoxFirstName.Text, textBoxMI.Text);
			SessionFacade.SaveOrUpdatePatient(p);
			Close();
		}
		
		void ButtonCancelClick(object sender, EventArgs e)
		{
			Close();
		}
		
		void ComboBoxChangeTabsSelectedIndexChanged(object sender, EventArgs e)
		{
			switch (comboBoxChangeTabs.SelectedIndex) {
				case 0:
					tabControl1.TabPages.Clear();
					tabControl1.TabPages.AddRange(new TabPage[] { tabPage1, tabPage2, tabPage3 });
					break;
				case 1:
					tabControl1.TabPages.Clear();
					tabControl1.TabPages.AddRange(new TabPage[] { tabPage4 });
					break;
				default:
					break;
			}
		}
	}
}
